﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI;
using System.Web;

namespace Esint.Common.Web
{
    public class EasyUI
    {
        public  class Message
        {
            public static void ShowMessage(int width, int height, string title, string msg)
            {
                Page page = HttpContext.Current.Handler as Page;

                System.Web.UI.WebControls.Literal local = new System.Web.UI.WebControls.Literal();
                local.ID = "local";


                local.Text = "<div style=\"width:" + width + "px;height:" + height + "px;\" id=\"msg\" title=\"" + title + "\">" + msg + "</div>";
                page.Form.Controls.Add(local);
                System.Web.UI.ScriptManager.RegisterStartupScript(page, page.GetType(), "msg", "$('#msg').dialog({ modal:true,buttons:[{text:'Ok',iconCls:'icon-ok',handler:function(){	$('#msg').dialog('close');} }]});", true);
            }

            public static void ShowMessage(string msg)
            {
                Page page = HttpContext.Current.Handler as Page;

                System.Web.UI.WebControls.Literal local = new System.Web.UI.WebControls.Literal();
                local.ID = "local";


                local.Text = "<div style=\"width:250px;height:180px;\" id=\"msg\" title=\"信息\">" + msg + "</div>";
                page.Form.Controls.Add(local);
                System.Web.UI.ScriptManager.RegisterStartupScript(page, page.GetType(), "msg", "$('#msg').dialog({ modal:true,buttons:[{text:'Ok',iconCls:'icon-ok',handler:function(){	$('#msg').dialog('close');} }]});", true);
            }
   
        }


        public class Window
        {
            public static void OpenWindow(int width, int height, string title, System.Web.UI.UserControl control)
            {
                Page page = HttpContext.Current.Handler as Page;
                System.Web.UI.WebControls.Panel p = new System.Web.UI.WebControls.Panel();
                p.Style.Value = "width:" + width + "px;height:" + height + "px;";
                p.ID = "msg";
                p.Attributes.Add("title", title);
                p.Controls.Add(control);
                page.Form.Controls.Add(p);
                System.Web.UI.ScriptManager.RegisterStartupScript(page, page.GetType(), "msg", "$('#" + p.ClientID + "').dialog({ modal:true,buttons:[{text:'Ok',iconCls:'icon-ok',handler:function(){	$('#" + p.ClientID + "').dialog('close');} }]});", true);
            }

            public static void OpenWindow(int width, int height, string title,string url,string refscript)
            {
                Page page = HttpContext.Current.Handler as Page;
                System.Web.UI.WebControls.Panel p = new System.Web.UI.WebControls.Panel();
                p.Style.Value = "width:" + width + "px;height:" + height + "px;";
                p.ID = "msg";
                p.Attributes.Add("title", title);

                System.Web.UI.WebControls.Literal local = new System.Web.UI.WebControls.Literal();
                local.Text = "<iframe src=\""+url+"\"  frameborder=\"0\"  style=\"height:100%;width:100%;overflow:hidden;\"></iframe>";

                p.Controls.Add(local);
                page.Form.Controls.Add(p);  
                System.Web.UI.ScriptManager.RegisterStartupScript(page, page.GetType(), "msg", "<script defer=\"defer\">$('#" + p.ClientID + "').dialog({ modal:true});</script>", false);
                System.Web.UI.ScriptManager.RegisterStartupScript(page, page.GetType(), "msgfun", "<script defer=\"defer\">var returnValue ='';function closeWindow(retValue){$('#" + p.ClientID + "').dialog('close');returnValue=retValue; " + refscript + ";}</script>", false);
            }

            public static void OpenWindow(UpdatePanel panel, int width, int height, string title, string url, string refscript)
            {
                 System.Web.UI.WebControls.Panel p = new System.Web.UI.WebControls.Panel();
                p.Style.Value = "width:" + width + "px;height:" + height + "px;";
                p.ID = "msg";
                p.Attributes.Add("title", title);
                System.Web.UI.WebControls.Literal local = new System.Web.UI.WebControls.Literal();
                local.Text = "<iframe src=\"" + url + "\"  frameborder=\"0\" style=\"height:100%;width:100%;\"></iframe>";
                p.Controls.Add(local);
                panel.ContentTemplateContainer.Controls.Add(p);
    
                System.Web.UI.ScriptManager.RegisterStartupScript(panel.TemplateControl, panel.TemplateControl.GetType(), "smsg", "$('#" + p.ClientID + "').dialog({ modal:true});", true);
                System.Web.UI.ScriptManager.RegisterStartupScript(panel.TemplateControl, panel.TemplateControl.GetType(), "msgfun", "var returnValue ='';function closeWindow(retValue){$('#" + p.ClientID + "').dialog('close');returnValue=retValue; " + refscript + ";}", true);
                
            }
             

            public static void CloseWindow()
            {
                Page page = HttpContext.Current.Handler as Page;
                System.Web.UI.ScriptManager.RegisterStartupScript(page, page.GetType(), "", "<script  defer=\"defer\">parent.closeWindow('');</script>", false);
            }
            public static void CloseWindow(string returnValue)
            {
                Page page = HttpContext.Current.Handler as Page;
                System.Web.UI.ScriptManager.RegisterStartupScript(page, page.GetType(), "", "<script  defer=\"defer\">parent.closeWindow('" + returnValue + "');</script>", false);
            }
        }
    }
}
